
function! CocCurrentFunction()
    return get(b:, 'coc_current_function', '')
endfunction

function! CocGitStatus(...)
   return get(g:, 'coc_git_status', '')
endfunction

function! LightlineGitBlame() abort
  let blame = get(b:, 'coc_git_blame', '')
  return winwidth(0) > 120 ? blame : ''
endfunction

" let g:lightline = {
"       \ 'active': {
"       \   'left': [ [ 'mode', 'paste' ],
"       \             [ 'cocstatus', 'gitbranch', 'readonly', 'filename', 'modified', 'currentfunction' ] ],
"       \   'right':[
"       \     [ 'filetype', 'fileencoding', 'lineinfo', 'percent' ],
"       \     [ 'blame' ]
"       \   ],
"       \ },
"       \ 'component_function': {
"       \   'cocstatus': 'coc#status',
"       \   'currentfunction': 'CocCurrentFunction',
"       \   'blame': 'LightlineGitBlame',
"       \   'gitbranch': 'CocGitStatus'
"       \ },
"       \ }

let g:lightline = {
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ],
      \             [ 'relativepath', 'modified' ] ],
      \   'right':[
      \     [ 'filetype', 'fileencoding', 'lineinfo', 'percent' ],
      \     [ 'blame' ]
      \   ],
      \ },
      \ 'component_function': {
      \   'cocstatus': 'coc#status',
      \   'currentfunction': 'CocCurrentFunction',
      \   'blame': 'LightlineGitBlame',
      \   'gitbranch': 'CocGitStatus'
      \ },
      \ }


if &background=='light'
    let g:lightline.colorscheme = 'one'
else
    let g:lightline.colorscheme = 'wombat'
endif

let g:lightline.separator = get(g:lightline, 'separator', {})
let g:lightline.subseparator = get(g:lightline, 'subseparator', {})
let g:lightline.separator.left = "\ue0b0"
let g:lightline.separator.right = "\ue0b2"
let g:lightline.subseparator.left = "\ue0b1"
let g:lightline.subseparator.right = "\ue0b3"

function! s:toggle_background() abort
    if &background=='light'
        set background=dark
        let g:lightline.colorscheme = 'wombat'
    elseif &background=='dark'
        set background=light
        let g:lightline.colorscheme = 'one'
    endif

    call lightline#disable()
    call lightline#enable()
endfunction

command! ZToggleBackground call s:toggle_background()

function! s:goyo_enter()
  if executable('tmux') && strlen($TMUX)
    silent !tmux set status off
    silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
  endif
  set noshowmode
  set noshowcmd
  " set scrolloff=999
endfunction

function! s:goyo_leave()
  if executable('tmux') && strlen($TMUX)
    silent !tmux set status on
    silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
  endif
  set showmode
  set showcmd
  " set scrolloff=5
endfunction

autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
